//
//  UIImage+Extension.swift
//  sina
//
//  Created by shengxinwei on 16/5/28.
//  Copyright © 2016年 shengxinwei. All rights reserved.
//

import UIKit

extension UIImage {
//    //截取当前屏幕
//    class func snapShotCurrentWindow() -> UIImage {
//        let window = UIApplication.sharedApplication().keyWindow!
//        //开启图形上下文
//        UIGraphicsBeginImageContextWithOptions(window.bounds.size, false, UIScreen.mainScreen().scale)
//        //需要将window\中显示的内容移动到图形上下文中
//        window.drawViewHierarchyInRect(window.bounds, afterScreenUpdates: false)
//        //从图形上下文获取图片
//        let image = UIGraphicsGetImageFromCurrentImageContext()
//        //关闭图形上下文
//        UIGraphicsEndImageContext()
//        return image
//    }
//    
    class func snapShotCurrentWindow() -> UIImage {
        
        let window = UIApplication.sharedApplication().keyWindow!
        //开启图片上下文
        UIGraphicsBeginImageContextWithOptions(window.bounds.size, false, 0)
        //需要将window中显示的内容滑到图片上下文中
        window.drawViewHierarchyInRect(window.bounds, afterScreenUpdates: false)
        
        //从图形上下文中获取图片
        let image = UIGraphicsGetImageFromCurrentImageContext()
        
        //关闭图片上下文
        UIGraphicsEndImageContext()
        
        return image
    }
    
}
